package org.jeecg.modules.paycenter.service;

import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.paycenter.pay.dto.PayBillData;
import org.jeecg.modules.wlhy.bill.entity.HyCarrierBill;
import org.jeecg.modules.wlhy.bill.entity.HyCustomerBill;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
import org.jeecg.modules.wlhy.bill.service.*;
import org.jeecg.modules.wlhy.company.entity.HyCompany;
import org.jeecg.modules.wlhy.company.service.IHyCompanyService;
import org.jeecg.modules.wlhy.hydriverbank.service.IHyDriverBankService;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public abstract class BaseBankService {

    @Autowired protected IHyShippingNoteService hyShippingNoteService;
    @Autowired protected IHyDriverBankService hyDriverBankService;
    @Autowired protected IHyCompanyService hyCompanyService;

    @Autowired protected IHyCustomerBillService hyCustomerBillService;
    @Autowired protected IHyShippingNoteBillService hyShippingNoteBillService;
    @Autowired protected IHyDriverBillService hyDriverBillService;
    @Autowired protected IHyCarrierBillService hyCarrierBillService;
    @Autowired protected IHyBillService hyBillService;

    //region

    @Transactional
    public void savePayFailInfo(PayBillData payBillData) {
        HyShippingNote shippingNote = payBillData.getShippingNote();
        HyCustomerBill customerBill = payBillData.getCustomerBill();
        HyShippingNoteBill shippingNoteBill = payBillData.getShippingNoteBill();
        HyDriverBill driverBill = payBillData.getDriverBill();
        HyCarrierBill carrierBill = payBillData.getCarrierBill();

        hyShippingNoteService.updateById(shippingNote);
        hyShippingNoteBillService.updateById(shippingNoteBill);

        if (customerBill != null) {
            hyCustomerBillService.updateById(customerBill);
        }
        if (driverBill != null) {
            hyDriverBillService.updateById(driverBill);
        }
        if (carrierBill != null) {
            hyCarrierBillService.updateById(carrierBill);
        }
    }

    //endregion

    //region

    //获取分公司信息
    public Map<String,HyCompany> getCompanyMaps(){
        List<HyCompany> companyList = hyCompanyService.list();
        if(companyList == null || companyList.size()==0){
            throw new JeecgBootException("分公司信息不存在");
        }

        Map<String,HyCompany> companyMaps = new HashMap<>();
        for (HyCompany hyCompany : companyList) {
            companyMaps.put(hyCompany.getId(),hyCompany);
        }
        return companyMaps;
    }

    //endregion

}
